package com.xsh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xsh.constant.Constant;
import com.xsh.mapper.GoodsMapper;
import com.xsh.pojo.Goods;
import com.xsh.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public void addGoods(Goods goods) {
        goodsMapper.insert(goods);
    }

    @Override
    public Goods queryByGoodsId(int id) {
        return goodsMapper.selectById(id);
    }

    @Override
    public void updateGoods(Goods goods) {
        goodsMapper.update(goods);
    }

    @Override
    public void deleteGoods(int id) {
        goodsMapper.delete(id);
    }

    @Override
    public PageInfo<Goods> queryAll(Integer pageNum) {
        PageHelper.startPage(pageNum, Constant.PAGESIZE);
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsMapper.selectAll(), 5);
        return pageInfo;
    }
}
